<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="conversation.css" rel="STYLESHEET" type="text/css">
<title>Annotate Message</title>
  <script>
  
  </script>
</head>
<body>
<!--        Header         -->
<jsp:include page="scripts/headerAnnotate.jsp">
  <jsp:param name="title" value="Annotate Message" />
</jsp:include>
<jsp:include page="scripts/toggleLayer.js" />
<jsp:include page="scripts/highlight_message.jsp" />
<jsp:include page="scripts/confirm.js" />
<!--       Navigation        -->
<jsp:include page="scripts/mnavigation.jsp">
  <jsp:param name="action" value="annotate" />
</jsp:include>
<!--        Metadata         -->
<div>
<form:form commandName="message">
<table>
  <tr>
    <th width="150">Data Set ID</th>
    <td><c:out value="${message.conversation.dataset.datasetId}" /></td>
    <th>Conversation ID</th>
    <td><c:out value="${message.conversation.conversationId}" /></td>
    <th>Message ID</th>
    <td><c:out value="${message.messageId}" /></td>
  </tr>
  <tr>
    <th>Sequence</th>
    <td><c:out value="${message.sequence}" /></td>
    <th>Speaker</th>
    <td><c:if test="${message.speaker==1}">Librarian</c:if><c:if test="${message.speaker==2}">User</c:if> </td>
    <th>Type</th>
    <td><c:out value="${message.type}" /></td>
  </tr>
  <tr>
    <th>Date Time</th>
    <td colspan="5"><c:out value="${message.dateTime}" /></td>
  </tr>
  <tr>
    <th>Content</th>
    <td id="messageContent" colspan="5"><c:out escapeXml="false"
      value="${message.contentString}" /></td>
  </tr>
  <tr>
    <th>Note</th>
    <td colspan="5" align="center"><spring:bind path="message.note">
      <textarea cols="60" rows="3"
        name='<c:out value="${status.expression}"/>'><c:out
        value="${status.value}" /></textarea>
    </spring:bind></td>
  <tr>
    <th>Annotation</th>
    <td colspan="5">
			Dialogue Acts: 
			<a href="enterda.html?messageId=<c:out value='${message.messageId}'/>">[new]</a><br></br>
			<br />
			<c:forEach items="${message.dialogueActs}" var="da" varStatus="status">
				<c:if test="${da.user.userId == anno_user.userId}">
    <table class="inner" onMouseOver="updateMessage(<c:out value='${status.index}'/>, 'none')">
						<tr>
							<th>ID:</th>
							<td colspan="2"><c:out value="${da.dialogueActId}" /> <a
								href="annotatemessage.html?messageId=<c:out value='${message.messageId}'/>&delDaId=<c:out value='${da.dialogueActId}'/>">[delete]</a><br></br>
							</td>
							<th>Created:</th>
							<td><c:out value="${da.createdAt}" /></td>
						</tr>
						<tr>
						<th>User: </th>
						<td colspan="2"><c:out value="${da.user.userName}"></c:out>
						</td>
						<th>Priority:</th>
					<td>
					<form:select path="dialogueActArray[${status.index}].priority">
						<form:option value="1" label="Primary" />
						<form:option value="2" label="Secondary" />
					</form:select>					
					</td>
				</tr>
				<tr>
					<th>Text Segment</th>
					<td>
					Start with:
						</td>						
						<td>
					<form:select onchange="updateMessage(${status.index}, 'start')" path="dialogueActArray[${status.index}].startIndex">
						<form:option value="null" label="Please Select" />
						<form:options items="${message.wordList}" itemValue="index"
							itemLabel="word" />
					</form:select>
						</td>
						<td>
					End with:
						</td>						
						<td>
					<form:select onchange="updateMessage(${status.index}, 'end')" path="dialogueActArray[${status.index}].endIndex">
						<form:option value="null" label="Please Select" />
						<form:options items="${message.wordList}" itemValue="index"
							itemLabel="word" />
					</form:select>
					</td>
				</tr>
				<tr>
					<th>Dialogue Act</th>
					<td>
						Function:  
						</td>						
						<td>
         <form:select  onchange="updateMessage(${status.index}, 'foo')" path="dialogueActArray[${status.index}].function">    		
            <option value="null">Please select</option>
            <c:forEach items="${da_functions}" var="daLabel">
              <option value='<c:out value="${daLabel.dialogueActLabelId}"/>'
                <c:if test="${da.function.dialogueActLabelId == daLabel.dialogueActLabelId}">selected</c:if>>
                <c:out value="${daLabel.label}" />
              </option>
            </c:forEach>
          </form:select>
						</td>
						<td>
					  Domain:
						</td>						
						<td>
         <form:select path="dialogueActArray[${status.index}].domain">
            <option value="null">Please select</option>
            <c:forEach items="${da_domains}" var="daLabel">
              <option value='<c:out value="${daLabel.dialogueActLabelId}"/>'
                <c:if test="${da.domain.dialogueActLabelId == daLabel.dialogueActLabelId}">selected</c:if>>
                <c:out value="${daLabel.label}" />
              </option>
            </c:forEach>
          </form:select>
					</td>
				</tr>
				<tr>
					<th rowspan="2">Adjacency</th>
					<td>
						Relationship:					  
						</td>						
						<td colspan="3">
						  <form:select path="dialogueActArray[${status.index}].adjacency">
                <option value="null">Please select</option>
                <c:forEach items="${adjacencies}" var="adj">
                  <option value='<c:out value="${adj.adjacencyId}"/>'
                    <c:if test="${da.adjacency.adjacencyId == adj.adjacencyId}">selected</c:if>>
                    <c:out value="${adj.label}" />
                  </option>
                </c:forEach>
              </form:select>
			    </td>
			  </tr>
			  <tr>
			    <td>
				    To:
				  </td>						
				  <td colspan="3">
						<form:select path="dialogueActArray[${status.index}].adjacentDialogueAct">
              	<option value="null">Please select</option>
                <c:forEach items="${message.conversation.sortedDialogueActs}" var="sda">
                  <option value='<c:out value="${sda.dialogueActId}"/>'
                    <c:if test="${da.adjacentDialogueAct.dialogueActId == sda.dialogueActId}">selected</c:if>>
                    <c:out value="${sda.textForSelectOption}" />
                  </option>
                </c:forEach>
              </form:select>
				</tr>
			</table>
			</c:if>
      </c:forEach>
    </td>
  </tr>
  <tr>
    <td colspan="7">
      <input type="submit" value="Save" /> 
	</td>
	</tr>
	</table>
	</form:form>
</div>
<jsp:include page="scripts/footer.jsp" />
</body>
</html>
